@extends('Layout/adminBase')
@section('css')
<link rel="stylesheet" type="text/css" href="{{asset('/bootstrap/css/bootstrap.min.css')}}">
<link rel="stylesheet" href="{{asset('/bootstrap/css/bootstrap.min.css')}}" />
<style type="text/css">
    tr{
        text-align: center;
    }
    tr th{
         text-align: center;
    }
</style>
<script type="text/javascript" src="{{asset('/js/jquery.js')}}"></script>
<script type="text/javascript" src="{{asset('/bootstrap/js/bootstrap.min.js')}}"></script>
@endsection
@section('body')
<div class='container'>

    <table class="table table-condensed table-bordered table-striped">
        <caption>订单</caption>
        <thead>
            <tr>
                <th>序号</th>
                <th>订单号</th>
                <th>加入时间</th>
                <th>收件人</th>
                <th>收件电话</th>
                <th>收件地址</th>
                <th>金额</th>
                <th>积分</th>
                <th>支付状态</th>
                <th>订单状态</th>
                <th>物流状态</th>
                <th>查看详情</th>
                <th width="30%" align="center">操作</th>
            </tr>
        </thead>
        <tbody>
            @foreach ($detail as $v)

            <tr>
                <td>{{$v->id}}</td>
                <td>{{$v->order_number}}</td>
                <td>{{date("Y-m-d H:i:s",$v->create_at)}}</td>
                <td>{{$v->receiving_man}}</td>
                <td>{{$v->receiving_phone}}</td>
                <td>{{$v->receiving_address}}</td>
                <td id="price">{{$v->total_money}}</td>
                <td>{{$v->credits}}</td>
                <td>{{$pay_state[$v->pay_state]}}</td>
                <td>{{$order_state[$v->order_state]}}</td>
                <td>{{$logistics[$v->logistics]}}</td>
                <td> <a class="btn btn-default-sm" href="/admin/DetailController/detail/{{$v->id}}">查看详情</a></td>
                <td>

                      <!-- /admin/DetailController/shipments/{{$v->id}} -->
                    @if($v->pay_state == 1 && $v->logistics == 0)

                        <a class="btn btn-default-sm" href="javascript:;" id="shipments" data-id="{{$v->id}}" >发货</a>

                    @endif

                    @if($v->order_state == 0 && $v->logistics !=2 )

                            <a class="btn btn-default-sm" href="/admin/DetailController/change/{{$v->id}}" data-id="{{$v->id}}">修改</a>

                    @endif

                    @if($v->order_state != 2 && $v->pay_state !=1 )

                            <a class="btn btn-default-sm" href="javascript:;" id="refund" data-id="{{$v->id}}">取消订单</a>

                    @endif
                </td>
            </tr>
            @endforeach
        </tbody>
    </table>
    {{ $detail->links() }}
</div>

<script type="text/javascript">
  $('#shipments').on('click',function () {
    var id  = $("#shipments").attr("data-id");
    // var token  = "{{csrf_token()}}";
    $.ajax({
      type:'get',
      url:"/admin/shipments",
      data:{"id":id},
      dataType:'json',
      success:function (data) {

        if (data.code = 200) {
          alert(data.msg);
          location.reload();

        }
      },
      error:function  (data) {
        if (data.code = 403) {
           alert(data.msg);
           location.reload();
        }
      },
    });
  });

  //
  $('#refund').on('click',function () {

      var id  = $("#refund").attr("data-id");
      // var token  = "{{csrf_token()}}";
      $.ajax({
        type:'get',
        url:"/admin/refund",
        data:{"id":id},
        dataType:'json',
        success:function (data) {

          if (data.code = 200) {
            alert(data.msg);
            location.reload();

          }
        },
        error:function  (data) {
          if (data.code = 403) {
             alert(data.msg);
             location.reload();
          }
        },
    });
  })

</script>
@endsection
